﻿<ui:View x:Class="CPPEI.Coolzon.Designer.Views.SolutionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ui="clr-namespace:CPPEI.Coolzon.UI;assembly=CPPEI.Coolzon.UI"
             xmlns:local="clr-namespace:CPPEI.Coolzon.Designer.Views" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <ui:View.Resources>
        <local:NodeStatusToImage x:Key="nodeStatusToImage"/>
        <local:NodeTypeToImage x:Key="nodeTypeToImage"/>
        <local:NodeStatusToString x:Key="nodeStatusToString"/>
        <local:NodeTypeToString x:Key="nodeTypeToString"/>
        <local:SceneIdToThumbnailConverter x:Key="sceneIdToThumbnail"/>
        <Style x:Key="treeViewItemStyle" TargetType="{x:Type TreeViewItem}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Template" xmlns:s="clr-namespace:System;assembly=mscorlib" >
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TreeViewItem}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition  Width="16"/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Border Grid.ColumnSpan="2" Margin="-1600,0,0,0"  x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"  SnapsToDevicePixels="true"/>
                            <ToggleButton  x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" >
                                <ToggleButton.Style>
                                    <Style TargetType="ToggleButton">
                                        <Style.Resources>
                                            <ResourceDictionary />
                                        </Style.Resources>
                                        <Setter Property="UIElement.Focusable">
                                            <Setter.Value>
                                                <s:Boolean>False</s:Boolean>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter Property="FrameworkElement.Width">
                                            <Setter.Value>
                                                <s:Double>16</s:Double>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter Property="FrameworkElement.Height">
                                            <Setter.Value>
                                                <s:Double>16</s:Double>
                                            </Setter.Value>
                                        </Setter>
                                        <Setter Property="Control.Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ToggleButton">
                                                    <Border Padding="5,5,5,5" Background="#00FFFFFF" Width="16" Height="16">
                                                        <Path Fill="#00FFFFFF" Stroke="#FF989898" Name="ExpandPath">
                                                            <Path.Data>
                                                                <PathGeometry Figures="M0,0L0,6L6,0z" />
                                                            </Path.Data>
                                                            <Path.RenderTransform>
                                                                <RotateTransform Angle="135" CenterX="3" CenterY="3" />
                                                            </Path.RenderTransform>
                                                        </Path>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="ToggleButton.IsChecked">
                                                            <Setter Property="UIElement.RenderTransform" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <RotateTransform Angle="180" CenterX="3" CenterY="3" />
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#FF595959"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#FF262626"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Trigger.Value>
                                                                <s:Boolean>True</s:Boolean>
                                                            </Trigger.Value>
                                                        </Trigger>
                                                        <Trigger Property="UIElement.IsMouseOver">
                                                            <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#FF1BBBFA"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#00FFFFFF"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Trigger.Value>
                                                                <s:Boolean>True</s:Boolean>
                                                            </Trigger.Value>
                                                        </Trigger>
                                                        <MultiTrigger>
                                                            <MultiTrigger.Conditions>
                                                                <Condition Property="UIElement.IsMouseOver">
                                                                    <Condition.Value>
                                                                        <s:Boolean>True</s:Boolean>
                                                                    </Condition.Value>
                                                                </Condition>
                                                                <Condition Property="ToggleButton.IsChecked">
                                                                    <Condition.Value>
                                                                        <s:Boolean>True</s:Boolean>
                                                                    </Condition.Value>
                                                                </Condition>
                                                            </MultiTrigger.Conditions>
                                                            <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#FF262626"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush Color="#FF595959"></SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </MultiTrigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ToggleButton.Style>
                            </ToggleButton>
                            <ContentPresenter Grid.Column="1" x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            <ItemsPresenter  x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsExpanded" Value="false">
                                <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                            </Trigger>
                            <Trigger Property="HasItems" Value="false">
                                <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background" TargetName="Bd" >
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Background" TargetName="Expander">
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd">
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                                    </Setter.Value>
                                </Setter>

                                <Setter Property="Background" TargetName="Expander" >
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" />
                                    </Setter.Value>
                                </Setter>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
                    <Setter Property="ItemsPanel">
                        <Setter.Value>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel/>
                            </ItemsPanelTemplate>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ui:View.Resources>
    <DockPanel x:Name="dpLayout">
        <TreeView x:Name="tvSolution" SelectedItemChanged="tvSolution_SelectedItemChanged" ScrollViewer.HorizontalScrollBarVisibility="Auto" ContextMenuOpening="tvSolution_ContextMenuOpening" PreviewMouseRightButtonDown="tvSolution_PreviewMouseRightButtonDown"  >
            <TreeView.ItemContainerStyle>
                <Style BasedOn="{StaticResource treeViewItemStyle}" TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding Path=IsSelected,Mode=TwoWay}" />
                    <EventSetter Event="TreeViewItem.MouseDoubleClick" Handler="TreeViewItem_MouseDoubleClick" />
                </Style>
            </TreeView.ItemContainerStyle>
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate DataType="{x:Type local:SolutionTreeViewNode}" ItemsSource="{Binding Children}"  >
                    <StackPanel Orientation="Horizontal"  >
                        <Image Source="{Binding Path=NodeStatus, Converter={StaticResource nodeStatusToImage}}" Height="16" Margin="5,0,0,0">
                            <Image.ToolTip >
                                <TextBlock VerticalAlignment="Center" Text="{Binding Path=NodeStatus, Converter={StaticResource nodeStatusToString}}" TextWrapping="Wrap" MaxWidth="200" ></TextBlock>
                            </Image.ToolTip>
                        </Image>
                        <Image Source="{Binding Path=NodeType, Converter={StaticResource nodeTypeToImage}}" Height="16"  Margin="5,0,0,0" >
                            <Image.ToolTip>
                                <TextBlock VerticalAlignment="Center" Text="{Binding Path=NodeType, Converter={StaticResource nodeTypeToString}}" TextWrapping="Wrap" MaxWidth="200" ></TextBlock>
                            </Image.ToolTip>
                        </Image>
                        <local:EditableTextBlock Tag="{Binding Path=Tag}"  Height="22"  Margin="5,0,0,0"  VerticalAlignment="Center" HorizontalAlignment="Center" IsInEditMode="{Binding Path=IsInEditMode, Mode=TwoWay}"  Text="{Binding Path=Header}" EndEdit="Rename_EndEdit" >
                            <local:EditableTextBlock.ToolTip>
                                <ToolTip BorderThickness="0" Background="Transparent">
                                    <Grid Background="#33000000">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <TextBlock Grid.Row="0" VerticalAlignment="Center" Text="{Binding Path=ToolTip}" TextWrapping="Wrap" HorizontalAlignment="Left" Margin="5,0,0,0" MaxWidth="200" FontSize="14" FontWeight="Bold"></TextBlock>
                                        <Image Grid.Row="1" Source="{Binding Path=ID, Converter={StaticResource sceneIdToThumbnail}}" MaxWidth="300" MaxHeight="300" />
                                    </Grid>
                                </ToolTip>
                            </local:EditableTextBlock.ToolTip>
                        </local:EditableTextBlock>

                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
            <TreeView.ContextMenu>
                <ContextMenu Name="cm" StaysOpen="True">
                    <MenuItem Name="_addScene" Header="新建场景" Command="local:UICustomCommand.AddScene" />
                    <MenuItem Name="_addFolder" Header="新建文件夹" Command="local:UICustomCommand.AddFolder" />
                    <MenuItem Name="_addResource" Header="新建资源文件" Command="local:UICustomCommand.AddResource" Visibility="Collapsed" />
                    <MenuItem Name="_addExisted" Header="添加已存在文件" Command="local:UICustomCommand.AddExisted" />
                    <Separator/>
                    <MenuItem Name="_getLatestVersion" Header="获取最新版本" Command="local:UICustomCommand.GetLatestVersion" />
                    <MenuItem Name="_checkIn" Header="签入" Command="local:UICustomCommand.CheckIn" />
                    <MenuItem Name="_checkOut" Header="签出" Command="local:UICustomCommand.CheckOut" />
                    <MenuItem Header="方案文件版本">
                        <MenuItem Header="撤销修改" Command="local:UICustomCommand.UndoPendingChanges"></MenuItem>
                        <MenuItem Header="查看历史" Command="local:UICustomCommand.ViewHistory" ></MenuItem>
                        <MenuItem Header="获取特定版本" Command="local:UICustomCommand.GetSpecificVersion" ></MenuItem>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Name="_displayflow" Header="配置演示顺序" Command="local:UICustomCommand.Displayflow" />
                    <Separator/>
                    <MenuItem Name="_scriptconfig" Header="配置脚本" Command="local:UICustomCommand.ScriptConfig" />
                    <MenuItem Name="_shortcutAction" Header="自定义操作" Command="local:UICustomCommand.ShortcutAction" />
                    <MenuItem Name="_commentsLink" Header="配置演讲文稿" Command="local:UICustomCommand.CommentsLink" />
                    <MenuItem Name="_newTemplate" Header="新建模板" Command="local:UICustomCommand.NewTemplate" />
                    <Separator/>
                    <MenuItem Name="_delete" Header="删除" Command="local:UICustomCommand.Delete" />
                    <MenuItem Name="_rename" Header="重命名" Command="local:UICustomCommand.Rename" />
                    <Separator/>
                    <MenuItem Name="_viewStatus" Header="查看状态" Command="local:UICustomCommand.ViewStatus" />
                    <MenuItem Name="_properties" Header="属性" Command="local:UICustomCommand.Properties" />
                </ContextMenu>
            </TreeView.ContextMenu>
        </TreeView>
    </DockPanel>
</ui:View>
